home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2001 May / SGI Freeware 2001 May - Disc 1.iso / dist / fw_mysql.idb / usr / freeware / share / sql-bench / test-create.z / test-create
Encoding:
Text File  |  1999-10-18  |  5.6 KB  |  234 lines

  1. #!/bin/perl5
  2. #
  3. # This test is for testing how long it takes to create tables,
  4. # make a count(*) from them and finally drop the tables. These
  5. # commands will be done in different ways in this test.
  6. # Using option --fast will drop all the tables in the end
  7. # of this test with one command instead of making own
  8. # 'drop' command for each and every table.
  9. # By changing the variable '$table_amount' value you can make
  10. # this test a lot harder/easier for your computer to drive.
  11. # Note that when using value bigger than 64 for this variable
  12. # will do 'drop table'-command    in totally different way because of that
  13. # how MySQL handles these commands.
  14.  
  15. ##################### Standard benchmark inits ##############################
  16.  
  17. use DBI;
  18. use Benchmark;
  19.  
  20. $opt_loop_count=1000; # Change this to make test harder/easier
  21. # This is the default value for the amount of tables used in this test.
  22.  
  23. chomp($pwd = `pwd`); $pwd = "." if ($pwd eq '');
  24. require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
  25.  
  26. if ($opt_small_test)
  27. {
  28.   $opt_loop_count/=10;
  29. }
  30.  
  31. print "Testing the speed of creating and droping tables\n";
  32. print "All tests are done $opt_loop_count times\n\n";
  33.  
  34. ####
  35. ####  Connect and start timeing
  36. ####
  37.  
  38. $dbh = $server->connect();
  39.  
  40. ### Here we'll make a loop $opt_loop_count times, which includes 1 create table,
  41. ### 1 count * from table and 1 drop table. Then we'll check how much
  42. ### time did it take.
  43.  
  44. if ($opt_force) # If tables used in this test exist, drop 'em
  45. {
  46.   print "Okay..Let's make sure that our tables don't exist yet.\n\n";
  47.   for ($i=1 ; $i<=$opt_loop_count ; $i++)
  48.   {
  49.     $dbh->do("drop table bench_$i");
  50.   }
  51. }
  52.  
  53. if ($opt_fast && $opt_server eq "pg")
  54. {
  55.   $server->vacuum($dbh);
  56. }
  57.  
  58. print "Testing create of tables\n";
  59.  
  60. $loop_time=$start_time=new Benchmark;
  61.  
  62. for ($i=1 ; $i <= $opt_loop_count ; $i++)
  63. {
  64.   do_many($dbh,$server->create("bench_$i",
  65.                    ["i int NOT NULL",
  66.                 "d double",
  67.                 "f float",
  68.                 "s char(10)",
  69.                 "v varchar(100)"],
  70.                    ["primary key (i)"]));
  71. }
  72.  
  73. $end_time=new Benchmark;
  74. print "Time for create_table ($opt_loop_count): " .
  75.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  76.  
  77. if ($opt_fast && $opt_server eq "pg")
  78. {
  79.   $server->vacuum($dbh);
  80. }
  81.  
  82. #### Here comes $opt_loop_count couples of cont(*) to the tables.
  83. #### We'll check how long it will take...
  84. ####
  85.  
  86. print "Accessing tables\n";
  87.  
  88. if ($limits->{'group_functions'})
  89. {
  90.   $query="select count(*) from ";
  91.   $type="select_group";
  92. }
  93. else
  94. {
  95.   $query="select * from ";
  96.   $type="select";
  97. }
  98.  
  99. $loop_time=new Benchmark;
  100. for ($i=1 ; $i <= $opt_loop_count ; $i++)
  101. {
  102.   $sth = $dbh->do("$query bench_$i") or die $DBI::errstr;
  103. }
  104.  
  105. $end_time=new Benchmark;
  106. print "Time to $type ($opt_loop_count): " .
  107.     timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  108.  
  109. ####
  110. #### Now we are going to drop $opt_loop_count tables;
  111. ####
  112.  
  113. print "Testing drop\n";
  114.  
  115. $loop_time=new Benchmark;
  116.  
  117. if ($opt_fast && $server->{'limits'}->{'multi_drop'} &&
  118.     $server->{'limits'}->{'query_size'} > 11+$opt_loop_count*10)
  119. {
  120.   my $query="drop table bench_1";
  121.   for ($i=2 ; $i <= $opt_loop_count ; $i++)
  122.   {
  123.     $query.=",bench_$i";
  124.   }
  125.   $sth = $dbh->do($query) or die $DBI::errstr;
  126. }
  127. else
  128. {
  129.   for ($i=1 ; $i <= $opt_loop_count ; $i++)
  130.   {
  131.     $sth = $dbh->do("drop table bench_$i")
  132.       or die $DBI::errstr;
  133.   }
  134. }
  135.  
  136.  
  137. $end_time=new Benchmark;
  138. print "Time for drop_table ($opt_loop_count): " .
  139.     timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  140.  
  141. if ($opt_fast && $opt_server eq "pg")
  142. {
  143.   $server->vacuum($dbh);
  144. }
  145.  
  146. #### We'll do first one 'create table' and then we'll drop it
  147. #### away immediately. This loop shall be executed $opt_loop_count
  148. #### times.
  149.  
  150. print "Testing create+drop\n";
  151.  
  152. $loop_time=new Benchmark;
  153.  
  154. for ($i=1 ; $i <= $opt_loop_count ; $i++)
  155. {
  156.   do_many($dbh,$server->create("bench_$i",
  157.                    ["i int NOT NULL",
  158.                 "d double",
  159.                 "f float",
  160.                 "s char(10)",
  161.                 "v varchar(100)"],
  162.                    ["primary key (i)"]));
  163.   $sth = $dbh->do("drop table bench_$i") or die $DBI::errstr;
  164. }
  165.  
  166. $end_time=new Benchmark;
  167. print "Time for create+drop ($opt_loop_count): " .
  168.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  169.  
  170. if ($opt_fast && $opt_server eq "pg")
  171. {
  172.   $server->vacuum($dbh);
  173. }
  174.  
  175. #
  176. # Same test, but with a table with many keys
  177. #
  178.  
  179. my @fields=(); my @keys=();
  180. $keys=min($limits->{'max_index'},16);        # 16 is more than enough
  181. $seg= min($limits->{'max_index_parts'},$keys,16);    # 16 is more than enough
  182.  
  183. # Make keys on the most important types
  184. @types=(0,0,0,1,0,0,0,1,1,1,1,1,1,1,1,1,1);    # A 1 for each char field
  185. push(@fields,"field1 tinyint not null");
  186. push(@fields,"field2 mediumint not null");
  187. push(@fields,"field3 smallint not null");
  188. push(@fields,"field4 char(16) not null");
  189. push(@fields,"field5 integer not null");
  190. push(@fields,"field6 float not null");
  191. push(@fields,"field7 double not null");
  192. for ($i=8 ; $i <= $keys ; $i++)
  193. {
  194.   push(@fields,"field$i char(5) not null");    # Should be relatively fair
  195. }
  196.  
  197. # Let first key contain many segments
  198. my $query="primary key (";
  199. for ($i= 1 ; $i <= $seg ; $i++)
  200. {
  201.   $query.= "field$i,";
  202. }
  203. substr($query,-1)=")";
  204. push (@keys,$query);
  205.  
  206. #Create other keys
  207. for ($i=2 ; $i <= $keys ; $i++)
  208. {
  209.   push(@keys,"index index$i (field$i)");
  210. }
  211.  
  212. $loop_time=new Benchmark;
  213. for ($i=1 ; $i <= $opt_loop_count ; $i++)
  214. {
  215.   do_many($dbh,$server->create("bench_$i", \@fields, \@index));
  216.   $dbh->do("drop table bench_$i") or die $DBI::errstr;
  217. }
  218.  
  219. $end_time=new Benchmark;
  220. print "Time for create_key+drop ($opt_loop_count): " .
  221.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  222.  
  223. if ($opt_fast && $opt_server eq "pg")
  224. {
  225.   $server->vacuum($dbh);
  226. }
  227.  
  228. ####
  229. #### End of benchmark
  230. ####
  231.  
  232. $dbh->disconnect;                # close connection
  233. end_benchmark($start_time);
  234.